package com.ptmall.app.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.PopupWindow;

import com.ptmall.app.R;
import com.ptmall.app.utils.AllUtils;


/**
 * Created by MacBook on 17/3/23.
 */

public class GetPhotoPop implements View.OnClickListener{
    private PopupWindow popupWindow;
    private Context context;
    private View view;
    private Window window;
    private OnClickPhoto onClickPhoto;
    public void setOnClickPhoto(OnClickPhoto onClickPhoto){
        this.onClickPhoto = onClickPhoto;
    }
    public GetPhotoPop(Context context, Window window) {
        this.context = context;
        this.window = window;
        initView();
        initData();
    }
    private void initView(){
        view = LayoutInflater.from(context).inflate(R.layout.personaldata_pop, null);
        view.findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickPhoto.OnClickGallery();
                popupWindow.dismiss();
            }
        });
        view.findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickPhoto.OnClickPhotoGraph();
                popupWindow.dismiss();
            }
        });
        view.findViewById(R.id.btn_cancel).setOnClickListener(this);
    }
    private void initData(){
        popupWindow=new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,true);
        popupWindow.setAnimationStyle(R.style.dialogAnim);
        popupWindow.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
        AllUtils.backgroundAlpha(0.5f,window);
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
            AllUtils.backgroundAlpha(1f,window);

            }
        });

    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.btn_cancel) {
            popupWindow.dismiss();

        }
    }

    public interface OnClickPhoto{
        //图库
        void OnClickGallery();
        void OnClickPhotoGraph();
    }
}
